package com.jt.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.enums.modelEnums;
import com.jt.mapper.InventoryMapper;
import com.jt.pojo.Inventory;
import com.jt.pojo.Logs;
import com.jt.service.Impl.InventoryServiceImpl;
import com.jt.util.RestReturn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jt
 * @date 2024/8/3 16:44
 */
@Api(tags = "库存管理")
@RequestMapping("/inventory")
@RestController
@CrossOrigin(origins = "*")
public class InventoryController {

    @Autowired
    private InventoryServiceImpl inventoryService;

    @ApiOperation("获取库存")
    @GetMapping("/getInventoryList")
    public RestReturn getInventoryList() {
        try {
            List<Inventory> inventory = this.inventoryService.list(new QueryWrapper<Inventory>().orderByAsc("id"));
            return RestReturn.success(inventory);
        } catch (Exception e) {
            return RestReturn.fail(e.getMessage());
        }
    }

    @ApiOperation("更新库存列表")
    @PostMapping("/updateInventory")
    public RestReturn updateInventory(@RequestBody @Validated Inventory inventory){
        try {
            this.inventoryService.saveOrUpdate(inventory);
            return RestReturn.success(inventory);
        } catch (Exception e) {
            return RestReturn.fail(e.getMessage());
        }
    }
}
